package com.itboye.mengwu.luntan.comment.adapter;

import java.util.List;

import org.w3c.dom.Text;

import android.content.Context;
import android.graphics.Color;
import android.provider.ContactsContract.CommonDataKinds.Relation;
import android.text.Html;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alipay.android.phone.mrpc.core.r;
import com.itboye.mengwu.R;
import com.itboye.mengwu.data.model.TieZiBaoHanReply.GetAList.ReplyInfo.ReContent;
import com.itboye.mengwu.data.model.TieZiBaoHanReplyBaoBaoLe;
import com.itboye.mengwu.luntan.comment.bean.Reply;

public class CommentReplyAdapter extends BaseAdapter {
	private LayoutInflater inflater;
	private ViewHolder viewHolder;
	private OnClickListener replyToReplyListener;
	private int parentPosition = -1;
	private List<TieZiBaoHanReplyBaoBaoLe.GetAList.ReplyInfo.ReContent> replyList;
	Context context;

	public CommentReplyAdapter(
			Context context,
			List<TieZiBaoHanReplyBaoBaoLe.GetAList.ReplyInfo.ReContent> replyList,
			int parentPosition, OnClickListener replyToReplyListener) {
		this.inflater = LayoutInflater.from(context);
		this.parentPosition = parentPosition;
		this.replyToReplyListener = replyToReplyListener;
		this.replyList = replyList;
		this.context = context;
	}

	@Override
	public int getCount() {
		int count = replyList.size();
		return replyList.size();
	}

	public void clearList() {
		this.replyList.clear();
	}

	public void updateList(
			List<TieZiBaoHanReplyBaoBaoLe.GetAList.ReplyInfo.ReContent> replyList) {
		this.replyList.addAll(replyList);
	}

	@Override
	public TieZiBaoHanReplyBaoBaoLe.GetAList.ReplyInfo.ReContent getItem(
			int position) {
		return replyList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.item_comment_reply_small,
					null);
			viewHolder = new ViewHolder();
			viewHolder.tv_comment_reply_writer = (TextView) convertView
					.findViewById(R.id.tv_msg_content);
			viewHolder.re = (RelativeLayout) convertView.findViewById(R.id.re);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();

		}
		TieZiBaoHanReplyBaoBaoLe.GetAList.ReplyInfo.ReContent reply = getItem(position);
		System.out.println(">>>>>>id" + reply.getId());
		if (!reply.getId().equals("0")) {// 回复评论
			viewHolder.tv_comment_reply_writer.setText((Html
					.fromHtml("<font color=#FF6EA5>" + reply.getAuthor()
							+ "</font>" + "<font color=#8c8c8c>" + "回复"
							+ "</font>" + "<font color=#FF6EA5>"
							+ reply.getToUinfo().getNickname() + "</font> ：")));
			viewHolder.tv_comment_reply_writer.append(reply.getComment());
		} else {// 评论
			viewHolder.tv_comment_reply_writer.setText((Html
					.fromHtml("<font color=#FF6EA5>" + reply.getAuthor()
							+ "</font>" + ":")));
			viewHolder.tv_comment_reply_writer.append(reply.getComment());
		}
		// 记录发表回复时，对应的position,用于确定所回复的对象，如果是楼中楼，还需记录父节点的position
		convertView.setTag(R.id.tag_first, parentPosition);
		convertView.setTag(R.id.tag_second, position);
		convertView.setTag(R.id.tag_third, reply.getAuthorId());
		convertView.setTag(R.id.tag_fourth, reply.getId());
		convertView.setOnClickListener(replyToReplyListener);
		return convertView;
	}

	public class ViewHolder {
		private TextView tv_comment_reply_writer, huifu; // 评论者昵称 回复文字
		private TextView tv_comment_reply_text; // 评论 内容\
		private TextView tv_comment_reply_writer2; // 评论者昵称
		private TextView tv_comment_reply_text2; // 评论 内容
		private LinearLayout huifupinglun;//
		RelativeLayout re;
	}
}
